package com.mymail.test;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.mymail.entity.Receiver;

public class ReceiverDAO extends DAOImp {
	public boolean getById(Integer id,Receiver rec){
		String sql="select * from `receiver` where `receiver_id`=?";
		return this.findOne(sql, new Object[]{id}, rec);
	}
	
	@SuppressWarnings("unchecked")
	public ArrayList getReceivers(Integer mail_id){
		String sql="select * from `receiver` where `mail_id`=?";
		return this.findArray(sql, new Object[]{mail_id});
	}
	
	protected Receiver getEntity(ResultSet result) throws SQLException {
		Receiver rec=new Receiver();
		setAtribute(result,rec);
		return rec;
	}

	protected void setAtribute(ResultSet result, Object obj) throws SQLException{
		Receiver rec=(Receiver)obj;
		try {
			rec.setId(result.getInt("receiver_id"));
			rec.setName(result.getString("receiver_name"));
			rec.setSort((char)result.getString("receiver_sort").getBytes()[0]);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	

}
